﻿/// <reference path="jquery-1.6.4-vsdoc.js" />
$(document).ready(function () {
    for (var i = 0; i <= 10; i++) {
        $("select").append("<option>" + i + "</option>");
    }
    $("#Button1").click({ dd: 1 }, function (e) {
        alert(e.data.dd);
    });

    $("select").change(function () {

        var className = $(this).attr("class");
        var objects = $("." + className).filter('select');
        var target;
        for (var i = 0; i < objects.length; i++) {
            if ($(objects[i]).attr("id") != $(this).attr("id")) {
                target = objects[i];
            }
        }
        var Max = $($('input[id$="' + className + '"]')[0]).val();
        var originValue = $(this).val();
        var targetValue = $(target).val();
        var targetMax = Max - originValue;
        var twoHandAllCount = $($(target).parent().children()[2]).val();
        if (targetMax > twoHandAllCount) {
            targetMax = twoHandAllCount;
        }
        $(target).empty();
        for (var i = 0; i <= targetMax; i++) {
            $(target).append("<option>" + i + "</option>");
        }
        if (targetMax <= targetValue) {
            $(target).val(targetMax);
        }
        else {
            $(target).val(targetValue);
        }
        //        for (objectitem in $(".hello")) {
        //        $.each($(".hello"), function (objectitem) {
        //            if (objectitem != $(this)) {
        //                $(objectitem).attr("value", "fdsfsdfsd");
        //            }
        //            //            $(objectitem).attr("value", "fdsfsdfsd");
        //        });

    });
    //$('select[id$="ApplyQtyDropDownList"] :last-child').attr("selected", "selected");
}
);


var w = window.screen.width - 200;
var h = window.screen.height - 400;
window.moveTo(100, 200);
window.resizeTo(w, h);
$(document).ready(function () {
    $('input[id$="CheckBoxAll"]').change(function () {
        var x = $(this).attr("checked");
        if ($(this).attr("checked")) {
            $('input[id$="CheckBoxOne"]', $(this).parent().parent().parent()).attr("checked", "true");
        }
        else {
            $('input[id$="CheckBoxOne"]', $(this).parent().parent().parent()).removeAttr("checked");
        }
    }
            );

    //选择最大值
    //            $('select :last-child').attr("selected", "selected");
    $('select').each(function (index, element) {
        var value = $($(this).parent().children()[2]).val();
        //                $($(element).children()[value+1]).attr("selected", "selected");
        var object = $(this)[0];
        //                $($(this)[0]).parent().val(value);
        object = $(this).each(function (index1) {
            return index == index1;
        })
        //                .attr("selected", "selected");

    });

    //            $("select").val($($(this).parent().children()[2]).val());

    //实现新物料和二手物料 下拉列表的联动。 以 AppliationItemId 和 Material code 组成的Class 作为区分；
    $("select").change(function () {
        var className = $(this).attr("class");
        var objects = $("." + className).filter('select');
        var target;
        for (var i = 0; i < objects.length; i++) {
            if ($(objects[i]).attr("id") != $(this).attr("id")) {
                target = objects[i];
            }
        }
        var Max = $($(target).parent().children()[1]).val();
        var originValue = $(this).val();
        var targetValue = $(target).val();
        var targetMax = Max - originValue;
        //防止选的二手材料超过库存
        //                var twoHandAllCount = $($(target).parent().children()[2]).val();
        //                if (twoHandAllCount != 0 && targetMax > twoHandAllCount) {
        //                    targetMax = twoHandAllCount;
        //                }

        //                $(target).empty();
        //                for (var i = 0; i <= targetMax; i++) {
        //                    $(target).append("<option>" + i + "</option>");
        //                }
        //                if (targetMax <= targetValue) {
        //                    $(target).val(targetMax);
        //                }
        //                else {
        //                    $(target).val(targetValue);
        //                }
        if ((originValue + targetValue) > Max) {
            $(target).val(Max - originValue);
        }
    });

});


//收缩物料编辑行
$(function () {
    $('.printTitle span').hover(function () {
        $(this).addClass('hover')
    }, function () {
        $(this).removeClass('hover')
    }).click(
            function () {
                $(this).toggleClass('click').parent().next('.detailDiv').slideToggle();

            }
             );
});



//选择最大值
//            $('select :last-child').attr("selected", "selected");
$('select').each(function (index, element) {
    var value = $($(this).parent().children()[2]).val();
    var object = $($(this).parent().children()[0]);
    $($(this).parent().children()[0]).children().filter(function (index1) {
        return index1 == value;
    }).attr("selected", "selected");
});







//实现新物料和二手物料 下拉列表的联动。 以 AppliationItemId 和 Material code 组成的Class 作为区分；
$("select").change(function () {
    var className = $(this).attr("class");
    var objects = $("." + className).filter('select');
    var target;
    for (var i = 0; i < objects.length; i++) {
        if ($(objects[i]).attr("id") != $(this).attr("id")) {
            target = objects[i];
        }
    }
    var Max = $($(target).parent().children()[1]).val();
    var originValue = $(this).val();
    var targetOriginValue = $(target).val();
    var targetValue = Max - originValue;
    var afterAllValue = parseInt(originValue) + parseInt(targetOriginValue); // parseInt 如果不加 会是两个字符串相加 即字符串相连
    if (afterAllValue > Max) {
        $(target).val(targetValue);
    }
});



//打印向导
function printGuide(contractId) {
    var w = window.screen.width - 200;
    var h = window.screen.height - 400;
    window.moveTo(100, 200);
    window.resizeTo(w, h);
    contractId = $("#<%=hfApplicationId.ClientID %>").val();
    var randomValue = Math.random();
    var url = "PrintGuideDepot.aspx?ApplicationID=" + contractId;
    var w = 550;
    var h = 350;
    var strLocation = 'height=' + h + ', width=' + w + ', top=100, left=200, menubar=no, scrollbars=yes, resizable=yes,location=no, status=no';
    window.open(url, '', strLocation);
}